# -*- coding: utf-8 -*-

#    OriginDB
#    Copyright (C) 2010  Brian Plattenburg <alphastryk@gmail.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


from dbobject import DBObject
from aeConn import dbHandle

import yaml

class Filter(DBObject):

	def __init__(self):

		DBObject.__init__(self)

		self.key = ''

		#List of catalyst object
		self._things['catalysts'] = []

		#List of equCompound objects or compound objects
		self._things['reactants'] = []
		self._things['products'] = []

		#Integers
		self._things['temperature'] = None
		self._things['pressure'] = None
		self._things['time'] = None
		self._things['pH'] = None

		#Strings
		self._things['solvent'] = ''
		self._things['other'] = ''

		#bools
		self._things['liquid'] = False
		self._things['gas'] = False
		self._things['solid'] = False

		self._things['maxtemperature'] = None
		self._things['maxpressure'] = None
		self._things['maxtime'] = None
		self._things['maxpH'] = None

	def _loadYAML(self, yml):
		raise NotImplementedError

	def _dumpYAML(self, properties=[]):
		print "Trying to export a filter"

		if properties:
			keys = properties
		else:
			keys = self.properties().keys()

		data = {}

		print keys

		if "catalysts" in keys:
			keys.remove("catalysts")
			data["catalysts"] = [i.key for i in self.catalysts]
		if "products" in keys:
			keys.remove("products")
			data["products"] = {}
			for i in self.products:
				print i, i.key, i._loaded
				data["products"] = [i.key for i in self.products]
		if "reactants" in keys:
			keys.remove("reactants")
			data["reactants"] = {}
			for i in self.reactants:
				data["reactants"] = [i.key for i in self.reactants]

		rest = list(set(keys) - set(data.keys()))
		print rest
		print "Aux data: ", data
		return DBObject._dumpYAML(self, otherData=data, properties=rest)

	def forceUpdate(self):
		raise NotImplementedError
		
	def load(self):
		raise NotImplementedError
		
	def search(self):
		raise NotImplementedError

	def __eq__(self, other):
		return object.__eq__(self, other)

	def __del__(self):
		pass
